import http from "@/util/request";

/**
 * 分页获取商品列表
 * @param {*} page 当前页
 * @param {*} size 每页显示数量
 * @param {*} count 从那一条开始获取
 * @param {*} sort 排列方式
 * @returns
 */
const getGoodsList = (page = 1, size = 20, count = 0, sort = "all") => {
  return http.get("goods/list", {
    params: {
      page,
      size,
      count,
      sort,
    },
  });
};

//分页获取收藏商品列表
const getGoodsCollect = (page = 1, size = 10, count = 0, sort = "all") => {
  return http.get("goods/collect", {
    params: {
      page,
      size,
      count,
      sort,
    },
  });
};

//根据id获取商品信息
const getGoods = (id) => {
  return http.get("goods/one", {
    params: {
      id,
    },
  });
};

/**
 * //获取购物商品
 * @param {Array} data 加入购物车商品数组
 * @returns
 */
const getCartList = (data) => {
  return http.get("goods/cart", {
    params: {
      arr: JSON.stringify(data),
    },
  });
};

//收藏/取消收藏 商品
const userCollect = (data) => {
  return http.post("goods/collect", JSON.stringify(data));
};

//搜索商品
const searchGoods = (val) => {
  return http.get("goods/search", {
    params: {
      val,
    },
  });
};

export default {
  getGoodsList,
  getGoodsCollect,
  getGoods,
  userCollect,
  searchGoods,
  getCartList,
};
